<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
</head>
<body>
 <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

<script type="text/html" id="currentTableBar">
     <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="add">新增</a>
     <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="update">修改</a>
</script>
<script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="../../js/common/constant.js"></script>
<script>
    layui.use(['form', 'table'], function () {
        var util = layui.util;
        var $ = layui.jquery,
        form = layui.form,
        table = layui.table;
        url = getRootPath();

        table.render({
            elem: '#currentTableId',
            url: url+'/web/financial-product-type/list',
            toolbar: '#toolbarDemo',
            response: {
                statusCode: 200  //设置返回值状态码的默认值
            },
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {type: "checkbox", width: 50},
                {field: 'id', width: 200, title: '类型编号',templet: '<div>{{d.productType.id}}</div>',sort: true },
                {field: 'typeName', width: 200, title: '类型名称',templet: '<div>{{d.productType.typeName}}</div>',sort: true},//,templet:function(d){return util.toDateString(d.Plandate, "yyyy-MM-dd");}
                {field: 'description', width: 300, title: '类型描述', templet: '<div>{{d.productType.description}}</div>',sort: true},
                {field: 'craeteTime', width: 200, title: '类型创建日期',templet: '<div>{{d.productType.craeteTime}}</div>'},
                {field: 'productNumber', title: '类型产品个数', Width: 100},
                // {field: 'planremark', width: 200, title: '状态'},
                {title: '操作', minWidth: 280, toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true,
            skin: 'line',
        });
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'add') {
            
                var index = layer.open({
                    title: '新增计划项',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['60%', '40%'],
                    content: '../product/product-type-add.html',
                });
            }
            else if (obj.event === 'update'){ 
                alert(JSON.stringify(data.id));
                
                    var index = layer.open({
                   title: '修改计划',
                   type: 2,
                   shade: 0.2,
                   maxmin:true,
                   shadeClose: true,
                   area: ['70%', '60%'],
                   content: '../product/product-type-update.html?id='+data.productType.id,
               });
            }


        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            layer.alert(result, {
                title: '最终的搜索信息'
            });

            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');

            return false;
        });
    });
</script>

</body>
</html>